package com.lepu.app.fun.chat.util;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.app.utils.Utils;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.utils.main.UIHelper;
import com.core.lib.utils.main.UtilityBase;
import com.lepu.app.fun.chat.activity.ChatMainActivity;
import com.lepu.app.fun.chat.bean.ChatMessage;
import com.lepu.app.fun.chat.bean.ChatSession;
import com.lepu.app.fun.chat.core.ChatManager;
import com.lepu.app.fun.chat.core.MessageBuilder;
import com.lepu.app.fun.my.bean.BeanLecture;
import com.lepu.app.fun.my.bean.BeanMyActivityDetail;
import com.lepu.app.main.permission.PermissionUtil;
import com.lepu.app.main.permission.callback.PermissionResultCallBack;
import com.lepu.pasm.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ChatUtil {

	// 账户进行校验
	public static boolean isRegexAccount(String reg) {
		return reg.matches("^[A-Za-z0-9]+$");
	}

	public static void jumpChat(final Activity activity, final ChatSession item, final int chatType) {
		if (activity != null && activity instanceof BaseFragmentActivity) {
			BaseFragmentActivity baseFragmentActivity = (BaseFragmentActivity) activity;

			Intent intent = new Intent(activity, ChatMainActivity.class);
			intent.putExtra("type", chatType);
			intent.putExtra("ChatSession", item);
			baseFragmentActivity.startActivity(intent, true);
		}
	}

	public static void jumpChat(final Activity activity, final int chatType, final BeanMyActivityDetail item) {
		if (activity != null && activity instanceof BaseFragmentActivity) {
			BaseFragmentActivity baseFragmentActivity = (BaseFragmentActivity) activity;

			Intent intent = new Intent(activity, ChatMainActivity.class);
			intent.putExtra("type", chatType);
			intent.putExtra("BeanMyActivityDetail", item);
			baseFragmentActivity.startActivity(intent, true);
		}
	}

	public static void sendChatNotice(String DoctorID)
	{
		ChatSession chatSession = new ChatSession();
		ChatMessage chatMessage = MessageBuilder.buildNewTextMessage(
				chatSession, "");
		chatMessage.setFromUserId(Constants.AskDoctorAddNotice);
		chatMessage.setToUserId(UtilityBase.parseLong(DoctorID));
		ChatManager.getInstance().sendMessageNotice(chatMessage);
	}

	public static String parseGroupChatContent(String content)
	{
//		StringBuilder result = new StringBuilder();
//
//		if(!TextUtils.isEmpty(content)){
//
//			try {
//				JSONArray jsonArray = new JSONArray(content);
//				for(int i=0;i<jsonArray.length();i++){
//					JSONObject obj = jsonArray.getJSONObject(i);
//					String name = obj.optString("NickName");
//					String userID = obj.optString("UserID");
//					String itemContent = obj.optString("Content");
//
//					if(TextUtils.isEmpty(name) && TextUtils.isEmpty(userID)){
//						result.append(itemContent);
//					}else{
//						result.append("@").append(name).append(itemContent);
//					}
//				}
//			} catch (JSONException e) {
//				e.printStackTrace();
//				result.append(content);
//			}
//		}
//		return result.toString();

		return content;
	}

}
